package com.wens.monitor.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.wens.monitor.model.User;

public class UserDAO extends DAO{
	
	public static User getUser(String username) {
		Session session = factory.getCurrentSession();
		session.beginTransaction();
		Query q = session.createQuery("from User u where u.name = :username")
				.setString("username", username);
		Object o = q.uniqueResult();
		session.getTransaction().commit();
		if (o != null)
			return (User)o;
		return null;
	}
	
	public static void update(User user) {
		Session session = factory.getCurrentSession();
		session.beginTransaction();
		session.update(user);
		session.getTransaction().commit();
	}
}
